import http from "@/http"
import type { DefaultData, DefaultHotData, DefaultLiveData } from "@/typings"
import type { DefaultDetailData, PlayerUrlData } from '@/TypingMore/VideoTyping'
import type { Bvid, Sections, DefaultMainSection, DefaultFData, DefaultIntroduction, DefalutFRecommend, DefalutReallySeason } from '@/TypingMore/SeasonTyping'
import type { DefaultLiveM3u8Data, DefaultKvlist, DafaultLiveMsg , GiftData, RoomgiftListGoldList, RechargeData} from '@/TypingMore/LiveTyping'
import type { DafaultHotWord, DafaultSuggestResult, DafaultSearchType, DafaultMediaBangumi } from '@/TypingMore/SearchTyping'
import type { DafaultUser, DafaultStat , DafaultVlist} from "@/TypingMore/UserTyping";
import type {  QrcodeData, isQrcode } from '@/TypingMore/PassTyping'
import type { DafaultIsPn , DafaultRankingAll} from '@/TypingMore/HomeIsPn'

// 主页分类
export const Api = {
    // 首页的分类数据
    getRankingData: (rid: string, typename: string) => {
        return http.request<DefaultData>({
            url: `/api/x/web-interface/ranking/region?rid=${rid}&day=7${typename === '推荐' ? '&context=' : ''}`,
            method: "get"
        })
    },
    // 更多分类
    getOtherList: (rid: string, index: number) => {
        return http.request<DafaultIsPn>({
            url: `/api/x/web-interface/dynamic/region?rid=${rid}&pn=${index}`,
            method: 'get'
        })
    },
    // 首页热门分类
    getHotData: () => {
        return http.request<DefaultHotData>({
            url: `/api/x/web-interface/wx/hot?ps=100&pn=1&teenage_mode=0`,
            method: 'get'
        })
    },
    // 直播数据
    getLiveData: () => {
        return http.request<DefaultLiveData>({
            url: `/live/room/v2/AppIndex/getAllList?device=phone&platform=ios&scale=3&build=10000&protocol=0,1&format=0,1,2&codec=0,1`,
            method: 'get'
        })
    },
    // 视频详情
    getDetailData: (bvid: string) => {
        return http.request<DefaultDetailData>({
            url: `/api/x/web-interface/view/detail?aid=&bvid=${bvid}&recommend_type=&need_rcmd_reason=1`,
            method: 'get'
        })
    },
    // 获取视频播放url
    getPlaymp4UrlData: (cid: number, avid: number) => {
        return http.request<PlayerUrlData>({
            url: `/api/x/player/playurl?avid=${avid}&cid=${cid}&qn=16&type=mp4&platform=html5`,
            method: 'get'
        })
    },
    // 获取sectonsid
    getSectionIdData: (ep_id: string) => {
        return http.request<Sections>({
            url: `/api/pgc/season/player/cards?ep_id=${ep_id}&platform=web`,
            method: 'get'
        })
    },
    // 获取选集
    getSectionData: (season_id: number) => {
        return http.request<DefaultMainSection>({
            url: `/api/pgc/web/season/section?season_id=${season_id}`,
            method: 'get'
        })
    },

    // 番剧的接口请求
    getFPlayUrlData: (ep_id: string) => {
        return http.request<DefaultFData>({
            url: `/api/pgc/player/web/playurl/html5?ep_id=${ep_id}&bsource=`,
            method: 'get',
        })
    },
    // 获取简介
    getSeason: (ep_id: string) => {
        return http.request<DefaultIntroduction>({
            url: `/api/pgc/view/web/season?ep_id=${ep_id}`,
            method: 'get'
        })
    },
    // 番剧相关推荐
    getRecommendData: (season_id: number) => {
        return http.request<DefalutFRecommend>({
            url: `/api/pgc/season/web/related/recommend?season_id=${season_id}`,
            method: 'get'
        })
    },

    // 电视剧的seactionId
    getSectionId: (epId: string) => {
        return http.request<DefalutReallySeason>({
            url: `https://api.bilibili.com/pgc/view/web/season?ep_id=${epId}`,
            method: 'get'
        })
    },

    // 弹幕数据
    getDanMu: (cid: number) => {
        return http.request<string>({
            url: `/danmu/${cid}.xml`,
            method: 'get',
            headers: {
                'content-type': 'text/xml'
            }
        })
    },

    // 相关数据获取bvid
    getBvid: (aid: number, cid: number, ep_id: string, season_id: number) => {
        return http.request<Bvid>({
            url: `/api/x/player/v2?aid=${aid}&cid=${cid}&ep_id=${ep_id}&season_id=${season_id}`
        })
    }
}
// 排行榜 
export const RankingAll = {
    // 获取排行榜数据
    getRankingAll: (rid: string) => {
        return http.request<DafaultRankingAll>({
            url: `/api/x/web-interface/ranking/v2?rid=${rid}`,
            method: 'get'
        })
    }
}
// 直播的数据
export const LiveApi = {
    // 获取直播视频
    getLiveM3u8Data: (room_id: number) => {
        return http.request<DefaultLiveM3u8Data>({
            url: `/live/xlive/web-room/v2/index/getRoomPlayInfo?room_id=${room_id}&protocol=0,1&format=0,1,2&codec=0,1&qn=10000&platform=web&ptype=8&dolby=5`,
            method: 'get'
        })
    },
    // 获取进入之后最开始展示的消息
    getLiveMsg: (room_id: number) => {
        return http.request<DafaultLiveMsg>({
            url: `/live/AppRoom/msg?room_id=${room_id}`
        })
    },
    // 获取直播提醒消息
    getLiveRemindMsg: () => {
        return http.request<DefaultKvlist>({
            url: `/live/xlive/open-interface/v1/fetch_client_resource?business=civilized_pledge:0`,
            method: 'get'
        })
    },
    // 所有的礼物品种
    getGitfDefaultData: () => {
        return http.request<RoomgiftListGoldList>({
            url: `/live/xlive/web-room/v1/giftPanel/giftData?room_id=26541495&ruid=18500072&area_id=192&area_parent_id=5&platform=pc&source=live`,
            method: 'get'
        })
    },
    // 获取礼物数据图片
    getGiftConfig: () => {
        return http.request<GiftData>({
            url: `/live/xlive/web-room/v1/giftPanel/giftConfig?platform=pc&room_id=26541495&area_parent_id=5&area_id=192`,
            method: 'get'
        })
    },
    // 获取充值价格
    getRechargeData: () => {
        return http.request<RechargeData>({
            url: `/live/xlive/revenue/v2/order/rechargePanel?context_type=1&build=0&platform=pc&need_hamster=1&t=1670757363013`,
            method: 'get'
        })
    },
    // // 直播表情
    // getEmoticonsData: () => {
    //     return http.request({
    //         url: "/publicdata/eomData.json",
    //         method: 'get'
    //     })
    // }
}
// 搜索的数据
export const SearchApi = {
    // 获取热门关键字
    getHotwordData: () => {
        return http.request<DafaultHotWord>({
            url: `/search/main/hotword`,
            method: 'get'
        })
    },
    // 搜索联想
    getSuggest: (term: string) => {
        return http.request<DafaultSuggestResult>({
            url: `/search/main/suggest?func=suggest&suggest_type=accurate&sub_type=tag&main_ver=v1&highlight=&bangumi_acc_num=3&special_acc_num=0&upuser_acc_num=0&tag_num=10&term=${term}&rnd=0.09559166064309288`,
            method: 'get'
        })
    },
    // 搜索结果默认排序
    getSearchResult: (keyword: string) => {
        return http.request<DafaultSearchType>({
            url: `/api/x/web-interface/search/all/v2?keyword=${keyword}&search_type=video&page=1&pagesize=20&context=`,
            method: 'get'
        })
    },
    // 搜索到的其它分类
    getOtherData: (keyword: string , search_type: string) => {
        return http.request<any>({
            url: `/api/x/web-interface/search/type?keyword=${keyword}&page=1&search_type=${search_type}&order=totalrank&pagesize=20`
        })
    },
    // cookie 需要携带这个不然不可以获取到搜索的结果
    getSpi: () => {
        return http.request({
            url: `/api/x/frontend/finger/spi`,
            method: 'get'
        })
    },
    // 搜索结果的其他分类
    getOtherChoiesData: (order: string, keyword: string) => {
      return http.request<any>({
        url: `/api/x/web-interface/search/type?keyword=${keyword}&page=1&search_type=video&order=${order}&pagesize=20`,
        method: 'get'
      })  
    },
    // 获取其他集数
    getOtherEpisodesData: (epId: number) => {
        return http.request<any>({
            url: `/api/pgc/view/web/season?ep_id=${epId}`,
            method: 'get'
        })
    }
}
// 用户的数据
export const UserApi = {
    // 用户的基本信息
    getUserBaseData: (mid: string) => {
        return http.request<DafaultUser>({
            url: `/api/x/space/acc/info?mid=${mid}&gaia_source=m_station`,
            method: 'get'
        })
    },
    // 用户的基本粉丝那些东西
    getUserStat: (mid: string) => {
        return http.request<DafaultStat>({
            url: `/api/x/relation/stat?vmid=${mid}`,
            method: 'get'
        })
    },
    // 用户发布的视频
    getUserPublishVideo: (mid: string) => {
        return http.request<DafaultVlist>({
            url: `/api/x/space/arc/search?pn=1&ps=50&order=click&keyword=&mid=${mid}&gaia_source=m_station`
        })
    }
}
// 我的页面数据
export const PassPort = {
    // 获取登录二维码，暂时用来当做支付二维码，没钱测真实接口，沙箱还没弄明白
    getPassPortUrl: () => {
        return http.request<QrcodeData>({
            url: `/pass/x/passport-login/web/qrcode/generate?source=main-mini`,
            method: 'get'
        })
    },

    //判断是否扫码
    scanCodeOrNot: (qrcode_key: string) => {
        return http.request<isQrcode>({
            url: `/pass/x/passport-login/web/qrcode/poll?qrcode_key=${qrcode_key}&source=main_mini`,
            method: 'get'
        })
    },
    //  用户基本信息吧应该
    getUserBaseData: () => {
        return http.request({
            url: `/api/x/web-interface/nav`,
            method: 'get'
        })
    }
}